<include file="public@head" />
</head>

<body>
    <div class="layui-fluid wrap js-check-wrap" id="component-tabs">
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">文章分类</div>
                    <div class="layui-card-body">
                        <div class="layui-tab">
                            <ul class="layui-tab-title">
                                <li class="layui-this"><a href="{:url('AdminCategory/index')}">分类管理</a></li>
                                <li><a href="{:url('AdminCategory/add')}">添加分类</a></li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <form class="layui-form" method="post" action="{:url('AdminCategory/index')}">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">分类名称:</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="keyword" required lay-verify="required" placeholder="请输入分类名称" autocomplete="off" class="layui-input" value="{$keyword|default=''}">
                                            </div>
                                            <input type="submit" class="layui-btn layui-btn-normal" value="搜索" />
                                            <a class="layui-btn layui-btn-danger" href="{:url('AdminCategory/index')}">清空</a>
                                        </div>
                                    </form>
                                    <form method="post" class="js-ajax-form layui-form" action="{:url('AdminCategory/listOrder')}">
                                        <div class="layui-btn-group">
                                            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm js-ajax-submit">{:lang('SORT')}</button>
                                            <button class="layui-btn layui-btn-normal layui-btn-sm js-ajax-submit" type="submit" data-action="{:url('AdminCategory/toggle',array('display'=>'1'))}" data-subcheck="true">
                                                {:lang('DISPLAY')}
                                            </button>
                                            <button class="layui-btn layui-btn-normal layui-btn-sm js-ajax-submit" type="submit" data-action="{:url('AdminCategory/toggle',array('hide'=>1))}" data-subcheck="true">{:lang('HIDE')}
                                            </button>
                                        </div>
                                        <empty name="keyword">
                                            <table class="layui-table" id="menus-table">
                                                <colgroup>
                                                    <col width="35">
                                                    <col width="60">
                                                    <col width="20">
                                                    <col>
                                                    <col>
                                                    <col width="30">
                                                    <col width="220">
                                                </colgroup>
                                                <thead>
                                                    <tr>
                                                        <th>
                                                            <input lay-skin="primary" type="checkbox" lay-filter="js-check-all" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                                                        </th>
                                                        <th>排序</th>
                                                        <th>ID</th>
                                                        <th>分类名称</th>
                                                        <th>描述</th>
                                                        <th>状态</th>
                                                        <th>操作</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    {$category_tree}
                                                </tbody>
                                                <thead>
                                                    <tr>
                                                        <th>
                                                            <input lay-skin="primary" type="checkbox" lay-filter="js-check-all" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                                                        </th>
                                                        <th>排序</th>
                                                        <th>ID</th>
                                                        <th>分类名称</th>
                                                        <th>描述</th>
                                                        <th>状态</th>
                                                        <th>操作</th>
                                                    </tr>
                                                </thead>
                                            </table>
                                            <else />
                                            <table class="layui-table">
                                                <colgroup>
                                                    <col width="35">
                                                    <col width="60">
                                                    <col width="20">
                                                    <col>
                                                    <col>
                                                    <col width="30">
                                                    <col width="220">
                                                </colgroup>
                                                <thead>
                                                    <tr>
                                                        <th>
                                                            <input lay-skin="primary" lay-filter="js-check-all" type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                                                        </th>
                                                        <th>排序</th>
                                                        <th>ID</th>
                                                        <th>分类名称</th>
                                                        <th>描述</th>
                                                        <th>状态</th>
                                                        <th>操作</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <foreach name="categories" item="vo">
                                                        <tr>
                                                            <td>
                                                                <input lay-skin="primary" type="checkbox" lay-filter="js-check" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" value="{$vo.id}">
                                                            </td>
                                                            <td>
                                                                <input name="list_orders[{$vo.id}]" type="text" size="3" value="{$vo.list_order}" class="input-order">
                                                            </td>
                                                            <td>{$vo.id}</td>
                                                            <td><a href="{cmf_url('portal/List/index', ['id' => $vo['id']])}" target="_blank">{$vo.name}</a>
                                                            </td>
                                                            <td>{$vo.description}</td>
                                                            <td>{$vo.status?'显示':'隐藏'}</td>
                                                            <td>
                                                                <a class="layui-btn layui-btn-normal" href="{:url('AdminCategory/add', ['parent' => $vo.id])}">添加子分类</a>
                                                                <a class="layui-btn layui-btn-normal" href="{:url('AdminCategory/edit',['id'=>$vo.id])}">编辑</a>
                                                                <a class="layui-btn layui-btn-normal js-ajax-delete" href="{:url('AdminCategory/delete',['id'=>$vo.id])}">删除</a>
                                                                <empty name="vo.status">
                                                                    <a class="layui-btn layui-btn-normal js-ajax-dialog-btn" data-msg="您确定显示此分类吗" href="{:url('AdminCategory/toggle',['ids'=>$vo.id,'display'=>1])}">显示</a>
                                                                    <else />
                                                                    <a class="layui-btn layui-btn-normal js-ajax-dialog-btn" data-msg="您确定隐藏此分类吗" href="{:url('AdminCategory/toggle',['ids'=>$vo.id,'hide'=>1])}">隐藏</a>
                                                                </empty>
                                                            </td>
                                                        </tr>
                                                    </foreach>
                                                </tbody>
                                                <thead>
                                                    <tr>
                                                        <th>
                                                            <input lay-skin="primary" lay-filter="js-check-all" type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                                                        </th>
                                                        <th>排序</th>
                                                        <th>ID</th>
                                                        <th>分类名称</th>
                                                        <th>描述</th>
                                                        <th>状态</th>
                                                        <th>操作</th>
                                                    </tr>
                                                </thead>
                                            </table>
                                        </empty>
                                        <div class="layui-btn-group">
                                            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm js-ajax-submit">{:lang('SORT')}</button>
                                            <button class="layui-btn layui-btn-normal layui-btn-sm js-ajax-submit" type="submit" data-action="{:url('AdminCategory/toggle',array('display'=>'1'))}" data-subcheck="true">
                                                {:lang('DISPLAY')}
                                            </button>
                                            <button class="layui-btn layui-btn-normal layui-btn-sm js-ajax-submit" type="submit" data-action="{:url('AdminCategory/toggle',array('hide'=>1))}" data-subcheck="true">{:lang('HIDE')}
                                            </button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <include file="public@footer" />
    <script>
    $(document).ready(function() {
        Wind.css('treeTable');
        Wind.use('treeTable', function() {
            $("#menus-table").treeTable({
                indent: 20,
                initialState: 'expanded'
            });
        });
    });

    // $(' #menus-table .js-check').change(function () {
    //     console.log('change');
    //     checkNode(this);
    // });
    //
    // function checkNode(obj) {
    //     var $obj   = $(obj);
    //     var $table = $obj.parents('table');
    //
    //     var id       = $obj.data('id');
    //     var parentId = $obj.data('parent_id');
    //
    //     function checkParent(id, parentId, checked) {
    //         console.log('checkParent:' + id);
    //         var $parent = $("tr [data-id='" + parentId + "']", $table);
    //         if ($parent.length > 0) {
    //             $parent.prop("checked", checked);
    //             checkParent($parent.data('id'), $parent.data('parent_id'), checked);
    //         }
    //     }
    //
    //     function checkChild(id, parentId, checked) {
    //         console.log('checkChild:' + id);
    //         var $child = $("tr [data-parent_id='" + id + "']", $table);
    //
    //         if ($child.length > 0) {
    //             $child.prop("checked", checked);
    //             checkChild($child.data('id'), $child.data('parent_id'), checked);
    //         }
    //     }
    //
    //     if ($obj.is(':checked')) {
    //         checkParent(id, parentId, true);
    //         checkChild(id, parentId, true);
    //     } else {
    //         checkParent(id, parentId, false);
    //         checkChild(id, parentId, false);
    //     }
    //     return;
    //     var chk   = $("input[type='checkbox']");
    //     var count = chk.length;
    //
    //     var num       = chk.index(obj);
    //     var level_top = level_bottom = chk.eq(num).attr('level');
    //     for (var i = num; i >= 0; i--) {
    //         var le = chk.eq(i).attr('level');
    //         if (le < level_top) {
    //             chk.eq(i).prop("checked", true);
    //             var level_top = level_top - 1;
    //         }
    //     }
    //     for (var j = num + 1; j < count; j++) {
    //         var le = chk.eq(j).attr('level');
    //         if (chk.eq(num).prop("checked")) {
    //
    //             if (le > level_bottom) {
    //                 chk.eq(j).prop("checked", true);
    //             }
    //             else if (le == level_bottom) {
    //                 break;
    //             }
    //         } else {
    //             if (le > level_bottom) {
    //                 chk.eq(j).prop("checked", false);
    //             } else if (le == level_bottom) {
    //                 break;
    //             }
    //         }
    //     }
    // }
    </script>
</body>

</html>